FROM python:3.11-slim

# 避免超时
ENV UV_HTTP_TIMEOUT=6000
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# 安装系统依赖（用于文档解析：doc, docx, excel）
# 注意：只安装 libreoffice-writer（轻量级，仅用于处理 .doc 文件）
# .docx 文件使用 python-docx，无需系统依赖
RUN apt-get update && apt-get install -y \
    libmagic1 \
    poppler-utils \
    tesseract-ocr \
    libreoffice-writer \
    && rm -rf /var/lib/apt/lists/*

# 使用阿里云 PyPI 镜像加速
RUN mkdir -p /etc/pip \
    && printf "[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\nextra-index-url = https://pypi.org/simple\n" > /etc/pip.conf

WORKDIR /app

# 先拷贝依赖清单以利用 Docker 层缓存
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt \
    || (rm -f /etc/pip.conf && pip install --no-cache-dir -i https://pypi.org/simple -r requirements.txt)

# 再拷贝剩余代码
COPY . .
# CMD ["python", "dss_file_search.py"]
# CMD ["sh", "-c", "python -u demo_ai_case_nature.py & python -u mcp_server_test.py"]
CMD ["python", "app.py"]
